// SteBitrateDlg.cpp : implementation file
//

#include "stdafx.h"
#include "RMSServer.h"
#include "RMSServerDlg.h"
#include "SetBitrateDlg.h"

#include "../Capture/CapLib.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSetBitrateDlg dialog
extern "C" {
extern double	LOGRUS_reqbitrate ; //default bitrate 1 Mbps
}

CSetBitrateDlg::CSetBitrateDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSetBitrateDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSetBitrateDlg)
	m_nBitrate = (UINT)(LOGRUS_reqbitrate*1024)/30;
	//}}AFX_DATA_INIT
}


void CSetBitrateDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSetBitrateDlg)
	DDX_Text(pDX, IDC_SIZEOFFRAME, m_nBitrate);
	DDV_MinMaxUInt(pDX, m_nBitrate, 0, 1000);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSetBitrateDlg, CDialog)
	//{{AFX_MSG_MAP(CSetBitrateDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSetBitrateDlg message handlers
extern bool bDisableCallback;

void CSetBitrateDlg::OnOK() 
{
	if(UpdateData(TRUE))
	{
		LONG lnRes;
		HKEY hKey;
		DWORD dwDisp;
		DWORD value;

		LOGRUS_reqbitrate = ((double)(m_nBitrate * 30)) / 1024.0;

		lnRes = RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Streambox Everywhere\\Settings",0,KEY_ALL_ACCESS,&hKey);
		if(ERROR_SUCCESS != lnRes)
		{
			lnRes = RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Streambox Everywhere\\Settings",0,NULL,
				REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,&dwDisp);
			if(ERROR_SUCCESS != lnRes)
			{
				RegCloseKey(hKey);
				return;
			}
		}
		value = (DWORD)(m_nBitrate);
		lnRes = RegSetValueEx(hKey,"Bit rate",NULL,REG_DWORD,(BYTE*)&(value),sizeof(DWORD));
		if(ERROR_SUCCESS != lnRes)
		{
			RegCloseKey(hKey);
			return;
		}

		RegCloseKey(hKey);

		CDialog::OnOK();
	}
}

int CSetBitrateDlg::DoModal() 
{
//	((CRMSServerDlg*)AfxGetMainWnd())->SetTimer(1,33,0);
	return CDialog::DoModal();
}
